package com.ysx.article.controller;

import com.ysx.article.dto.ApArticleDto;
import com.ysx.article.mapper.ApArticleConfigMapper;
import com.ysx.article.mapper.ApArticleContentMapper;
import com.ysx.article.mapper.ApArticleMapper;
import com.ysx.article.pojo.ApArticle;
import com.ysx.article.pojo.ApArticleConfig;
import com.ysx.article.pojo.ApArticleContent;
import com.ysx.article.service.ApArticleConfigService;
import com.ysx.article.service.ApArticleContentService;
import com.ysx.article.service.ApArticleService;
import com.ysx.common.pojo.Result;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Api(tags ="处理DTO数据 插入3个文章对象")
@RestController
@RequestMapping("/ApArticleDto")
public class ApArticleDtoController {
    //注入三个对象
    @Autowired
    private ApArticleMapper apArticleMapper;
    @Autowired
    private ApArticleConfigMapper apArticleConfigMapper;
    @Autowired
    private ApArticleContentMapper apArticleContentMapper;

    @PostMapping("/dto")
    public Result<ApArticle> saveDto(@RequestBody ApArticleDto apArticleDto) {
        ApArticle apArticle = apArticleDto.getApArticle();
        ApArticleConfig apArticleConfig = apArticleDto.getApArticleConfig();
        ApArticleContent apArticleContent = apArticleDto.getApArticleContent();
        //存储到数据库中
        apArticleMapper.insert(apArticle);
        apArticleConfigMapper.insert(apArticleConfig);
        apArticleContentMapper.insert(apArticleContent);
        //返回给数据库
        return Result.ok(apArticle);
    }


}
